package com.training.bt.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.time.LocalDateTime;

@TableName("tb_promotion")
@Data
public class Promotion {
    @TableId(type = com.baomidou.mybatisplus.annotation.IdType.AUTO)
    private  Long promotionId;
    private String promotionTitle; // 新增：促销标题 
    private String promotionRule;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    private Boolean isActive;
    private  Long creatorId;
    private Double discount;
    // 判断活动是否正在进行
    public boolean isInProgress() {
        LocalDateTime now = LocalDateTime.now();
        return isActive != null && isActive && startTime != null && endTime != null
                && now.isAfter(startTime) && now.isBefore(endTime);
    }


    public void setCreatorId( Long creatorId) { this.creatorId = creatorId; }
    public void setPromotionRule(String customRule) {
        if (discount != null) {
            this.promotionRule = String.format("（限时特价，%.1f折出售！！！）%s", discount, customRule);
        } else {
            this.promotionRule = customRule;
        }
    }
}